home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Enigma Amiga CD
/
Listati
/
67-Settembre-DIDATTICA-LIST.TX
< prev
next >
Wrap
Text File
|
1992-09-02
|
8KB
|
166 lines
/****************************************************************************
* Listato 1 *
* Questo programma apre una finestra con menù di esempio; il colore delle *
* opzioni dipende dagli IntuiText; quello di sfondo e di primo piano del *
* blocco e della barra dipendono dal FrontPen e BackPen nella definizione *
* della finestra; vi sono anche sotto-menù con mutua-esclusione. *
****************************************************************************/
#define INTUI_V36_NAMES_ONLY
/* inclusione file di supporto */
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <graphics/gfx.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/layers_protos.h>
#include <clib/dos_protos.h>
struct Library *IntuitionBase = NULL; /* puntatore a intuition.library */
struct Screen *pubscreen = NULL; /* puntatore al workbench */
struct Window *finestra = NULL; /* puntatore alla finestra */
struct MsgPort *UPort; /* puntatore alla porta IDCMP */
/* strutture definite per i menù */
struct IntuiText ItemText00 = {0,1,JAM2,0,1,NULL,"Nuovo",NULL};
struct IntuiText ItemText01 = {0,1,JAM2,0,1,NULL,"Apri...",NULL};
struct IntuiText ItemText02 = {0,1,JAM2,0,1,NULL,"Salva",NULL};
struct IntuiText ItemText03 = {0,1,JAM2,0,1,NULL,"Salva come...",NULL};
struct IntuiText ItemText04 = {0,1,JAM2,0,1,NULL,"Esci",NULL};
struct IntuiText ItemText10 = {0,1,JAM2,0,1,NULL,"Cut",NULL};
struct IntuiText ItemText11 = {0,1,JAM2,0,1,NULL,"Copy",NULL};
struct IntuiText ItemText12 = {0,1,JAM2,0,1,NULL,"Paste",NULL};
struct IntuiText ItemText13 = {0,1,JAM2,0,1,NULL,"Clear",NULL};
struct IntuiText ItemText20 = {0,1,JAM2,0,1,NULL,"Tipo",NULL};
struct IntuiText ItemText21 = {0,1,JAM2,0,1,NULL,"Caratteristiche",NULL};
struct IntuiText ItemText30 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Topaz",NULL};
struct IntuiText ItemText31 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Times",NULL};
struct IntuiText ItemText32 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Triumvirate",NULL};
struct IntuiText ItemText33 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Elvetica",NULL};
struct IntuiText ItemText34 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Diamond",NULL};
struct IntuiText ItemText40 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Plain",NULL};
struct IntuiText ItemText41 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Bold",NULL};
struct IntuiText ItemText42 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Italic",NULL};
struct IntuiText ItemText43 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Underline",NULL};
struct IntuiText ItemText44 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Outline",NULL};
#define MENUITEMFLAGS ITEMTEXT|ITEMENABLED|HIGHCOMP
struct MenuItem Item44 = {NULL,120,42,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText44,NULL,0,NULL,MENUNULL};
struct MenuItem Item43 = {&Item44,120,32,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText43,NULL,0,NULL,MENUNULL};
struct MenuItem Item42 = {&Item43,120,22,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText42,NULL,0,NULL,MENUNULL};
struct MenuItem Item41 = {&Item42,120,12,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText41,NULL,0,NULL,MENUNULL};
struct MenuItem Item40 = {&Item41,120,2,130,10,MENUITEMFLAGS|CHECKIT|CHECKED,0xFFFE,(APTR)&ItemText40,NULL,0,NULL,MENUNULL};
struct MenuItem Item34 = {NULL,120,42,130,10,MENUITEMFLAGS|CHECKIT,0xFFEF,(APTR)&ItemText34,NULL,0,NULL,MENUNULL};
struct MenuItem Item33 = {&Item34,120,32,130,10,MENUITEMFLAGS|CHECKIT,0xFFF7,(APTR)&ItemText33,NULL,0,NULL,MENUNULL};
struct MenuItem Item32 = {&Item33,120,22,130,10,MENUITEMFLAGS|CHECKIT,0xFFFB,(APTR)&ItemText32,NULL,0,NULL,MENUNULL};
struct MenuItem Item31 = {&Item32,120,12,130,10,MENUITEMFLAGS|CHECKIT,0xFFFD,(APTR)&ItemText31,NULL,0,NULL,MENUNULL};
struct MenuItem Item30 = {&Item31,120,2,130,10,MENUITEMFLAGS|CHECKIT|CHECKED,0xFFFE,(APTR)&ItemText30,NULL,'P',NULL,MENUNULL};
struct MenuItem Item21 = {NULL,0,10,130,10,MENUITEMFLAGS,0,(APTR)&ItemText21,NULL,0,&Item40,MENUNULL};
struct MenuItem Item20 = {&Item21,0,0,130,10,MENUITEMFLAGS,0,(APTR)&ItemText20,NULL,0,&Item30,MENUNULL};
struct MenuItem Item13 = {NULL,0,30,130,10,MENUITEMFLAGS,0,(APTR)&ItemText13,NULL,0,NULL,MENUNULL};
struct MenuItem Item12 = {&Item13,0,20,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText12,NULL,'P',NULL,MENUNULL};
struct MenuItem Item11 = {&Item12,0,10,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText11,NULL,'C',NULL,MENUNULL};
struct MenuItem Item10 = {&Item11,0,0,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText10,NULL,'X',NULL,MENUNULL};
struct MenuItem Item04 = {NULL,0,40,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText04,NULL,'E',NULL,MENUNULL};
struct MenuItem Item03 = {&Item04,0,30,200,10,MENUITEMFLAGS,0,(APTR)&ItemText03,NULL,0,NULL,MENUNULL};
struct MenuItem Item02 = {&Item03,0,20,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText02,NULL,'S',NULL,MENUNULL};
struct MenuItem Item01 = {&Item02,0,10,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText01,NULL,'A',NULL,MENUNULL};
struct MenuItem Item00 = {&Item01,0,0,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText00,NULL,'N',NULL,MENUNULL};
struct Menu sMenu2 = {NULL,172,0,58,8,MENUENABLED,"Fonts.",&Item20};
struct Menu sMenu1 = {&sMenu2,110,0,50,8,MENUENABLED,"Edit.",&Item10};
struct Menu sMenu0 = {&sMenu1,0,0,98,8,MENUENABLED,"Principale.",&Item00};
/* definizione prototipi di funzione */
void WaitEvent(struct MsgPort *,struct IntuiMessage *);
void CloseAll(void);
void OpenAll(void);
/* funzione per l'attesa di messaggi da Intuition */
void WaitEvent(struct MsgPort *porta,struct IntuiMessage *mess)
{
struct IntuiMessage *msg;
while ((msg = (struct IntuiMessage *)GetMsg(porta)) == NULL)
WaitPort(porta);
CopyMem(msg,mess,sizeof(struct IntuiMessage));
return;
}
/* procedura CloseAll() */
void CloseAll()
{
if (finestra != NULL) CloseWindow(finestra);
if (pubscreen != NULL) UnlockPubScreen(NULL,pubscreen);
if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
exit(0);
}
/* procedura OpenAll() */
void OpenAll()
{
/* apriamo intuition.library, almeno version 36 */
if ((IntuitionBase = OpenLibrary("intuition.library",36L)) == NULL)
CloseAll();
/* blocca lo schermo pubblico di default */
if ((pubscreen = LockPubScreen(NULL)) == NULL)
CloseAll();
/* apre finestra spostabile, con il gadget di chiusura */
if ((finestra = OpenWindowTags(NULL,WA_Left,10,
WA_Top,10,
WA_Width,350,
WA_Height,150,
WA_Title,"Esempio menù",
WA_DragBar,TRUE,
WA_CloseGadget,TRUE,
WA_DepthGadget,TRUE,
WA_Flags,WFLG_NOCAREREFRESH,
WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MENUPICK,
WA_PubScreen,pubscreen,
TAG_END)) == NULL)
CloseAll();
UPort = finestra -> UserPort;
return;
}
void main()
{
struct IntuiMessage mm;
UWORD MenuNum,Menu,MenuItem,MenuSubItem;
struct MenuItem *item;
OpenAll(); /* apre tutte le strutture dati */
SetMenuStrip(finestra,&sMenu0);
while(1)
{
WaitEvent(UPort,&mm); /* attende un evento */
if (mm.Class == IDCMP_CLOSEWINDOW) break; /* se gadget di chiusura esci */
else if (mm.Class == IDCMP_MENUPICK) /* selezione menù */
{
MenuNum = mm.Code;
while (MenuNum != MENUNULL)
{
item = ItemAddress(&sMenu0,MenuNum);
Menu = MENUNUM(MenuNum);
MenuItem = ITEMNUM(MenuNum);
MenuSubItem = SUBNUM(MenuNum);
printf("Selezionato menù: %d, opzione %d, sotto-opzione %d\n",Menu,MenuItem,MenuSubItem);
MenuNum = item -> NextSelect;
}
}
}
ClearMenuStrip(finestra);
CloseAll(); /* chiudi tutto ed esci */
}